package de.fmaul.dicheck.model;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Comment {
    private final String commenter;
    private final String text;

    public String getCommenter() {
        return commenter;
    }

    public String getText() {
        return text;
    }

    public Comment(final String commenter, final String text) {
        super();
        this.commenter = commenter;
        this.text = text;
    }

    public static Comment parseCommentFromSql(final String line) {
        Comment result = null;

        final Pattern p = Pattern.compile("--\\s+comment\\s+(.*)");
        final Matcher m = p.matcher(line);
        if (m.matches()) {
            final String content = m.group(1);

            final String[] parts = content.split("\\s*:\\s*");
            if (parts.length == 1) {
                result = new Comment("", parts[0]);
            } else if (parts.length == 2) {
                result = new Comment(parts[0], parts[1]);
            }
        }

        return result;
    }

}
